package map.landArea;

import java.util.Scanner;

public class noMain {
    static int[][] dir = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    public static void dfs(int[][] grid, int x, int y){
        grid[x][y] = 2;
        for (int i = 0; i < 4; i++) {
            int nextX = x + dir[i][0];
            int nextY = y + dir[i][1];
            if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length){
                continue;
            }
            if (grid[nextX][nextY] == 0 || grid[nextX][nextY] == 2){
                continue;
            }
            dfs(grid, nextX, nextY);
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int rows = scanner.nextInt();
        int cols = scanner.nextInt();
        int[][] lands = new int[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                lands[i][j] = scanner.nextInt();
            }
        }
        for (int i = 0; i < rows; i++) {
            if (lands[i][0] == 1){
                dfs(lands, i, 0);
            }
            if (lands[i][cols - 1] == 1){
                dfs(lands, i, cols - 1);
            }
        }
        for (int i = 0; i < cols; i++) {
            if (lands[0][i] == 1){
                dfs(lands, 0, i);
            }
            if (lands[rows - 1][i] == 1){
                dfs(lands, rows - 1, i);
            }
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (lands[i][j] == 1){
                    lands[i][j] = 0;
                }
                if (lands[i][j] == 2){
                    lands[i][j] = 1;
                }
            }
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                System.out.print(lands[i][j] + " ");
            }
            System.out.println();
        }
    }
}
